package com.azdebugit.springb.conman;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;

import java.net.ServerSocket;
import java.net.Socket;

@Slf4j
public class AgvWebApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(AgvWebApplication.class, args);
    }

    @Override
    public void run(String[] args) {
        try (ServerSocket serverSocket = new ServerSocket(8083);) {//1创建服务端
            log.info("服务端已启动，等待客户端连接..");
            for (; ; ) {
                try {
                    Socket socket = serverSocket.accept();
                    log.info("客户端加入,客户端IP[{}],端口号:[{}]",socket.getInetAddress(),socket.getPort());
                    ServerThread socketThread = new ServerThread(socket);
                    socketThread.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            log.info("error", e);
        }

    }


}